<?php

namespace App\Models\Products;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

/**
 * Class WeightClass
 * @package App\Models\Products
 *
 * @mixin Builder
 */

class WeightClass extends Model
{
    const WEIGHT_CLASS_VALUE_DEFAULT = 1.0; // 重量单位默认是kg

    protected $table = 'weight_class';
    protected $guarded = [];


    /**
     * @param $weight
     * @param $weight_class_id
     * @return float|int
     */
    public static function getWeightOption($weight, $weight_class_id)
    {
        $weight_class = (new self)->where('weight_class_id', $weight_class_id)
            ->first();

        $value = $weight_class->value ?? self::WEIGHT_CLASS_VALUE_DEFAULT;

        $weight_by_kg = $weight/$value;

        return $weight_by_kg;
    }
}
